Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent panic when image name and stage alias are the same #3245

Merged

Conversation

mickvangelderen
Copy link
Contributor

@mickvangelderen mickvangelderen commented Jul 10, 2024

Fixes #934

Description

Make sure a stage does not depend on itself.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
  • Adds integration tests if needed.

See the contribution guide for more details.

Reviewer Notes

  • The code flow looks good.
  • Unit tests and or integration tests added.

Reproduction:

echo -e 'FROM scratch AS scratch' > Dockerfile | tar -cf - Dockerfile | gzip -9 | docker run \
  --interactive -v $(pwd):/workspace gcr.io/kaniko-project/executor:v1.23.2 \
  --context tar://stdin \
  --no-push

Before:

INFO[0000] To simulate EOF and exit, press 'Ctrl+D'     
INFO[0000] Resolved base name scratch to scratch        
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running, locked to thread]:
github.com/GoogleContainerTools/kaniko/pkg/executor.CalculateDependencies({0xc0004260b0, 0x1, 0xc0003c3878?}, 0x2806b80, 0xc000796270)
	/src/pkg/executor/build.go:637 +0xc7a
github.com/GoogleContainerTools/kaniko/pkg/executor.DoBuild(0x2806b80)
	/src/pkg/executor/build.go:717 +0x225
github.com/GoogleContainerTools/kaniko/cmd/executor/cmd.init.func2(0xc00050ea00?, {0x196b03d?, 0x4?, 0x196b041?})
	/src/cmd/executor/cmd/root.go:190 +0x1b1
github.com/spf13/cobra.(*Command).execute(0x27f2540, {0xc000144050, 0x3, 0x3})
	/src/vendor/github.com/spf13/cobra/command.go:989 +0xab1
github.com/spf13/cobra.(*Command).ExecuteC(0x27f2540)
	/src/vendor/github.com/spf13/cobra/command.go:1117 +0x3ff
github.com/spf13/cobra.(*Command).Execute(0x197683e?)
	/src/vendor/github.com/spf13/cobra/command.go:1041 +0x13
main.main()
	/src/cmd/executor/main.go:31 +0x65

After:

INFO[0000] To simulate EOF and exit, press 'Ctrl+D'     
INFO[0000] Resolved base name scratch to scratch        
INFO[0000] Built cross stage deps: map[]                
INFO[0000] No base image, nothing to extract            
INFO[0000] Executing 0 build triggers                   
INFO[0000] Building stage 'scratch' [idx: '0', base-idx: '-1'] 
INFO[0000] Skipping unpacking as no commands require it. 
INFO[0000] Skipping push to container registry due to --no-push flag 

Release Notes

Describe any changes here so maintainer can include it in the release notes, or delete this block.

Examples of user facing changes:
- kaniko no longer panics when the image name and the stage name are the same

Copy link

google-cla bot commented Jul 10, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@mickvangelderen mickvangelderen changed the title Fix #934 Prevent panic when image name and stage alias are the same Jul 10, 2024
Copy link
Collaborator

@aaron-prindle aaron-prindle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the fix here @mickvangelderen!

@aaron-prindle aaron-prindle merged commit e108941 into GoogleContainerTools:main Jul 10, 2024
10 checks passed
@mickvangelderen mickvangelderen deleted the mickvangelderen/934 branch July 10, 2024 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic: index out of range when stage alias has the same name as base image
2 participants